<?php

namespace App\Http\Controllers\Agent;

use App\Models\Agent\TnetReginfo;
use App\Http\Controllers\Controller;
//实例化request
use Illuminate\Http\Request;
//use App\Agent;

class LoginController extends Controller {

	/**
	 * 区域代理后台
	 */
	public function login(Request $request)
	{
		if($request->isMethod('post')){
			#获取请求数据
			$nodecode=$request->input('nodecode');
			$userpwd=$request->input('userpwd');
			$tentReginfoModel=new TnetReginfo();
			#验证用户信息
			$checkInfo=$tentReginfoModel->checkAgentUser($nodecode,$userpwd,$request);
			if($checkInfo===true){
				return ['code'=>200,'message'=>$checkInfo];
			}else{
				return ['code'=>300,'message'=>$checkInfo];
			}
		}else{
			return view('Agent.login.login');
		}
	}

	/**
	 * 区域代理后台退出
	 */
	public function loginOut(Request $request){
		#清楚session
		session_start();
		$request->session()->pull('node_id', 'default');
		$request->session()->pull('name', 'default');
		$request->session()->pull('agent_id', 'default');
		unset($_SESSION['agent_id']);
		return \Redirect::to(route('agentLogin'));
	}

}